package com.yonyou.pmclouds.plan.util;

import com.yonyou.pmclouds.plan.entity.ScheduleItemVO;
import org.apache.commons.lang3.ArrayUtils;
import java.util.*;

/**
 * @Author chulf
 * @Date 2020/3/17
 * @Description 进度的计算，任务编码的赋值
 **/
public class ScheduleUtil {

    /**
     *
     * @param parent
     * @param tree
     *  计算编码
     */
    public static void genCodeOfTree(ScheduleItemVO parent, ScheduleItemVO[] tree) {
        for (ScheduleItemVO plan : tree) {
            if (parent == null) {
                plan.setCode(Integer.toString(plan.getSeq()));
            } else {
                plan.setCode(parent.getCode() + '.' + plan.getSeq());
            }
            ScheduleItemVO[] children = plan.getChildren();
            if (!ArrayUtils.isEmpty(children)) {
                // 递归应该不会出问题，最深20层
                genCodeOfTree(plan, children);
            }
        }

    }
}
